package com.itheima.d13_stringBuilder;

public class Test3 {
    public static void main(String[] args) {
        // 目标：完成遍历数组内容，并拼接成指定格式的案例。
        System.out.println(getArrayData(new int[]{11, 22, 33}));
    }

    public static String getArrayData(int[] arr) {

        if (arr == null) {
            return null;
        }
        StringBuilder sb = new StringBuilder("[");
        for (int i = 0; i < arr.length; i++) {
          /*  if (i == arr.length - 1) {
                sb.append(arr[i]);
            }else{
                sb.append(arr[i]+", ");
            }*/
            sb.append(i==arr.length-1?arr[i]:arr[i]+", ");

        }
        sb.append("]");
        System.out.println(sb);
        return sb.toString();
    }
}
